<template>
	<!-- 修改采购请求 -->
	<view>
		<view class="titlebox">
			<text class="text">修改请求</text>
		</view>
		<view class="boxcent">
			<view class="box1">
				<text class="text2 txt">日期:</text>
				<view class="datetime">
					<uni-datetime-picker type="date" v-model="production"></uni-datetime-picker>
				</view>
			</view>
			<view class="br"></view>
			<view class="box1" @click="stopage">
				<text class="text txt">商品名称:</text>
				<text class="text3">{{stoname}}</text>
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">规格:</text>
				<input class="text1" type="text" v-model="list.stospe">
			</view>
			<view class="br"></view>
			<view class="box1" @click="stopage">
				<text class="text txt">商品编号:</text>
				<text class="text3">{{stoid}}</text>
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">数量:</text>
				<input class="text1"  @input="get" type="text" v-model="list.num">
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">单价:</text>
				<input class="text1"  @input="get" type="text" v-model="list.purchase_price">
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">总金额:</text>
				<input class="text1" type="text" disabled="false" v-model="list.amount">
			</view>
			<view class="br"></view>
			<view class="box1" @click="suppage">
				<text class="text txt">供应商:</text>
				<text class="text3">{{supname}}</text>
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">经办人:</text>
				<text class="text3">{{list.whentryname}}</text>
			</view>
			<view class="br"></view>
			<view class="box1" @click="warpage">
				<text class="text txt">仓库名称:</text>
				<input class="text1" type="text" disabled="false" v-model="wname" placeholder="请选择仓库名称">
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">完成状态:</text>
				<text class="text3">{{list.whether}}</text>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">详情:</text>
				<input class="text1" type="text" v-model="list.title" placeholder="空">
			</view>
		</view>
		<view class="btnbox">
			<button @click="inst">保存</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',stoname:'',stoid:'',supname:'',supaccount:'',production:'1900-01-01',
				list:{},wname:''
			}
		},
		onLoad(option) {
			this.list = JSON.parse(option.item)
			this.production =this.list.data.substring(0, 10)
		},
		onShow:function(){
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var name=currPage.name;
			var id = currPage.id;
			if(name !==undefined){
				this.stoname = name
				this.stoid = id
			}else{
				this.stoname = this.list.stoname
				this.stoid = this.list.stoid
			}
			var sname=currPage.sname;
			var saccount = currPage.saccount;
			var spid = currPage.sid;
			var warname = currPage.warname;
			if(sname !==undefined){
				this.supname = sname
				this.supid = spid
				this.supaccount = saccount
			}else{
				this.supname = this.list.supname
				this.supaccount = this.list.bank_account
				this.supid = this.list.supid
			}
			var warname = currPage.warname;//仓库名称
			var warid = currPage.warid;//仓库编号
			if(warname !==undefined){
				this.wname = warname
				this.wid = warid
			}else{
				this.wname = this.list.wname
			}
		},
		methods: {
			get(){
				this.list.amount =this.list.num*this.list.purchase_price
			},
			async inst(){
				const res = await this.Request({
					url:'api/retgoods/upret',
					method:'PUT',
					data:{wname:this.wname,data:this.production,stoname:this.stoname,stospe:this.list.stospe,
						  stoid:this.stoid,num:this.list.num,purchase_price:this.list.purchase_price,
						  amount:this.list.amount,supid:this.supid,supname:this.supname,
						  whentryname:this.list.whentryname,title:this.list.title,id:this.list.id}
				})
				if(res.data.affectedRows=1){
					uni.showToast({
						title: '更新成功'
					})
					setTimeout(() => {
						var pages = getCurrentPages();
						var prePage = pages[pages.length - 3]; //上个页面
						prePage.name='show';  //赋值
						uni.navigateBack({
							delta:2
						})
					},500)
				}
			},
			stopage(){
				uni.navigateTo({
					url:'/pages/public/choose/choosegoods'
				})
			},
			suppage(){
				uni.navigateTo({
					url:'/pages/public/choose/choosesup?typevalue=入库'
				})
			},
			warpage(){
				uni.navigateTo({
					url:'/pages/public/choose/choosewar?typevalue=入库'
				})
			},
		}
	}
</script>

<style lang="scss">
	.titlebox{
		width: 100%;
		height: 30px;
		background-color: #efefef;
		display: flex;
		border-bottom: 1px solid #ccc;
		.text{
			margin: 5px 0 5px 5px;
			font-size: 110%;
			font-weight: 600;
			color: #008300;
		}
	}
	.boxcent{
		// margin-top: 10px;
		border-top: 2px solid #ccc;
		border-bottom: 2px solid #ccc;
		border-radius: 10px;
		position: relative;
		.br{
			height: 1px;
			margin-left: 10%;
			background: #a5a5a5;
		}
		.box1{
			display: flex;
			margin-top: 10px;
			margin-bottom: 10px;
			
			width: 100%;
			.txt{
				position: absolute;
				font-weight: 600;
				font-size: 110%;
			}
			.radio{
				position: relative;
				margin-left: 150px;
			}
			.radio1{
				position: relative;
				margin-left: 93px;
			}
			.img{
				position: absolute;
				height: 20px;
				width: 20px;
				margin-left: 355px;
			}
			.datetime{
				margin-left: 150px;
				width: 180px;
			}
			.text{
				margin-left: 10%;
			}
			.text1{
				margin-left: 170px;
			}
			.text2{
				margin-left: 10%;
				margin-top: 10px;
			}
			.text3{
				margin-left: 170px;
			}
		}
	}
	.btnbox{
		margin-top: 15px;
		margin-bottom: 60px;
		button{
			width: 50%;
			background-color: #ff5500;
			color: #ffffff;
		}
	}
</style>
